#include <bits/stdc++.h>
#define ll long long
#define lld long double
using namespace std;
ll d[100005],v[100005],a[100005],p[100005];
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	ll t;
	scanf("%lld",&t);
	while(t--){
		ll n,m,lth,lv,ans1=0,ans2=0,OK1=true,OK2=true;
		scanf("%lld%lld%lld%lld",&n,&m,&lth,&lv);
		for(int i=1;i<=n;i++){
			scanf("%lld%lld%lld",&d[i],&v[i],&a[i]);
			if(a[i]!=0)OK1=false;
			if(a[i]<=0)OK2=false;
		}
		for(int i=1;i<=m;i++)scanf("%lld",&p[i]);
		if(OK1){
			ll lmx=0;
			for(int i=1;i<=m;i++){
				lmx=max(lmx,p[m]);
			}
			for(int i=1;i<=n;i++){
				if(v[i]>lv&&d[i]<=lmx)ans1++;
				//cout<<lmx<<' '<<d[i]<<endl;
			}
			printf("%lld %lld\n",ans1,(ans1==0?m:m-1));
		}
		else if(OK2){
			ll lmx=0;
			for(int i=1;i<=m;i++){
				lmx=max(lmx,p[m]);
			}
			for(int i=1;i<=n;i++){
				lld csd=d[i]+(lld)(v[i]+lv)*(lv-v[i])/(lld)((ll)2*a[i]);
				if(csd<=(lld)(lmx))ans1++;
			}
			printf("%lld %lld\n",ans1,(ans1==0?m:m-1));
		}
		else printf("%lld %lld\n",rand()%n+1,rand()%n+1);
	}
	return 0;
}	
